﻿using Appliaction.Dto.Pinv;
using Appliaction.IAppServices.Pinv;
using Domain.Entitys.Pinv;
using Domain.IRepositorys.Pinv;
using EFCore.Repositorys.Pinv;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Reflection.Emit;

namespace API.Controllers.Pinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PoController : ControllerBase
    {
        private readonly IPoService poService;

        public PoController(IPoService poService)
        {
            this.poService = poService;
        }

        /// <summary>
        /// 条件查询总条数
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_Name"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetPoCount(string? Po_VendorName, string? Po_Name, string? proName)
        {
            return new JsonResult(poService.GetPoCount(Po_VendorName, Po_Name, proName));
        }
        [HttpGet]
        public JsonResult GetPoWhereCount2(string? Po_Vendor_Name, string? Po_Code, int Po_State, int Po_Rep_Id, int Po_depd_id)
        {
            return new JsonResult(poService.GetPoWhereCount(Po_Vendor_Name, Po_Code, Po_State, Po_Rep_Id, Po_depd_id));
        }
        /// <summary>
        /// 分页、条件查询
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_Name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetPoFYWhere(string? Po_VendorName, string? Po_Name, int currentPage, int pageSize, string? proName)
        {
            return new JsonResult(poService.GetPoFYWhere(Po_VendorName, Po_Name, currentPage, pageSize, proName));
        }
        [HttpGet]
        public async Task<JsonResult> GetPoWhere2(string? Po_Vendor_Name, string? Po_Code, int Po_State, int Po_Rep_Id, int Po_depd_id, int currentPage, int pageSize)
        {
            var data = await poService.GetPoWhere(Po_Vendor_Name, Po_Code, Po_State, Po_Rep_Id, Po_depd_id, currentPage, pageSize);
            return new JsonResult(data);
        }
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetPoWhere(string Po_VendorName)
        {
            var data = await poService.GetPoWhere(Po_VendorName);
            return new JsonResult(data);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> PostPoAdd([FromBody]PinvOrderDetailsDto<Pinv_Po_AddDto> pinvOrderDetailsDto)
        {
            return new JsonResult(await poService.PostPoAdd(pinvOrderDetailsDto));
        }
        [HttpPut]
        public async Task<IActionResult> PutPoDelete(PoDeleteDto pinv_Po)
        {
            var data = await poService.PutPoDelete(pinv_Po);
            return Ok(data);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> PutPoUpdate([FromBody] PinvOrderDetailsDto<Pinv_PoUpdateDto> PinvOrderDetailsDto)
        {
            return new JsonResult(await poService.PutPoUpdate(PinvOrderDetailsDto));
        }
        /// <summary>
        /// 根据采购订单查询采购明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Getdetailswherecode(string code)
        {
            var data = await poService.Getdetailswherecode(code);
            return new JsonResult(data);
        }
        /// <summary>
        /// 根据code审核
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> PutPoUpdateAudit(Pinv_PoUpdateAuditDto pinv_Po)
        {
            return new JsonResult(await poService.PutPoUpdateAudit(pinv_Po));
        }
        /// <summary>
        /// 根据采购订单编号已经条件查询明细
        /// </summary>
        /// <param name="code"></param>
        /// <param name="procode"></param>
        /// <param name="unitmeas_id"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetdetailswherecodeFY(string? code, string? procode, int unitmeas_id, int currentPage, int pageSize)
        {
            return new JsonResult(await poService.GetdetailswherecodeFY(code, procode, unitmeas_id, currentPage, pageSize));
        }
        /// <summary>
        /// 根据采购订单编号已经条件查询明细总条数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="procode"></param>
        /// <param name="unitmeas_id"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetdetailswherecodeFYCount(string? code, string? procode, int unitmeas_id)
        {
            return new JsonResult(poService.GetdetailswherecodeFYCount(code, procode, unitmeas_id));
        }
        /// <summary>
        /// 报表分页查询审核通过的
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_Name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetPoFYWhereAudit(string? Po_VendorName, string? Po_Name, int currentPage, int pageSize)
        {
            return new JsonResult(poService.GetPoFYWhereAudit(Po_VendorName, Po_Name, currentPage, pageSize));
        }
        //报表分页查询审核通过的总条数
        [HttpGet]
        public JsonResult GetPoCountAudit(string? Po_VendorName, string? Po_Name)
        {
            return new JsonResult(poService.GetPoCountAudit(Po_VendorName, Po_Name));
        }

        [HttpGet]
        public JsonResult Po_Details_OrdersSummary(string? Po_VendorName, string? Po_Name, string? proName)
        {
            return new JsonResult(poService.Po_Details_OrdersSummary(Po_VendorName,Po_Name,proName));
        }

        /// <summary>
        /// 采购订单撤销
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Pinv_PoRevokeAsync(Pinv_PoRevokeDto pinv_PoRevokeDto)
        {
            return new JsonResult(await poService.Pinv_PoRevokeAsync(pinv_PoRevokeDto));
        }
    }
}
